package com.wf.quartz;

import com.wf.constant.RedisConstant;
import com.wf.utils.AliOssUtil;
import com.wf.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author mpk
 * @since 2024/9/18 14:14:18
 */
@Slf4j
@Component
public class FileQuartz extends QuartzJobBean {

    @Autowired
    RedisUtil redisUtil;
    @Autowired
    AliOssUtil aliOssUtil;

    //定义具体执行的任务
    //TODO 垃圾图片定时清理
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        log.info("定时清除垃圾图片中...");
        Set<String> difference = redisUtil.difference(  RedisConstant.APARTMENT_ALL_FILE, RedisConstant.APARTMENT_USED_FILE);
        difference.stream()
                .forEach(
                        file ->{
                            aliOssUtil.delete(file);
                            redisUtil.setRemove(RedisConstant.APARTMENT_ALL_FILE, file);
                        }
                );
    }
}
